package gateway

import (
	"net/http"
	"io/ioutil"
	"bytes"
)

//get 请求
func Get(url string) (error, []byte) {
	out := make([]byte, 0)
	resp, err := http.Get(url)
	if err != nil {
		return err, out
	}
	defer resp.Body.Close()
	respBody, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err, out
	}
	return nil, respBody
}

// post 请求
func Post(url string, body []byte) (error, []byte) {
	out := make([]byte, 0)
	bytes.NewBuffer(body)
	resp, err := http.Post(url, "application/json", bytes.NewBuffer(body))
	if err != nil {
		return err, out
	}
	defer resp.Body.Close()
	respBody, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err, out
	}
	return nil, respBody
}
